/***************
 * User Activity Panel
 */
AIR2.User.Activity = function() {
    var formatSact = function(values) {
        var str = '';
        str += AIR2.Format.sourceFullName(values.Source, true);
        str += ' - ' + values.ActivityMaster.actm_name;
        str += ' - ' + values.sact_desc;
        return str;
    };
    var formatPact = function(values) {
        var user = AIR2.Format.userName(values.User, true) + ' ';
        var link = '';
        if (values.pa_ref_type == 'O') {
            link = ' ' + AIR2.Format.orgNameLong(values.Organization, true);
        } else if (values.pa_ref_type == 'I') {
            link = ' ' + AIR2.Format.inquiryTitle(values.Inquiry, true);
        }
        return user + values.ActivityMaster.actm_name + link;
    };
    var formatInq = function(values) {
        return 'Created the inquiry ' + AIR2.Format.inquiryTitle(values, true);
    };


    return new AIR2.UI.Panel({
        colspan: 2,
        title: 'Recent Activity',
        showTotal: true,
        iconCls: 'air2-icon-activity',
        storeData: AIR2.User.ACTDATA,
        url: AIR2.User.USERURL + '/activity',
        itemSelector: '.air2-user-act',
        tpl: new Ext.XTemplate(
            '<table><tpl for="."><tr class="air2-user-act">' +
              '<td><span class="type-icon ' +
                '<tpl if="SrcActivity">air2-icon-source</tpl>' +
                '<tpl if="ProjectActivity">air2-icon-project</tpl>' +
                '<tpl if="Inquiry">air2-icon-inquiry</tpl>' +
              '"></span></td>' +
              '<td>' +
                '<tpl if="SrcActivity">{[this.formatSact(values.SrcActivity)]}</tpl>' +
                '<tpl if="ProjectActivity">{[this.formatPact(values.ProjectActivity)]}</tpl>' +
                '<tpl if="Inquiry">{[this.formatInq(values.Inquiry)]}</tpl>' +
              '</td>' +
              '<td class="act-dtim">{dtim}</td>' +
            '</tr></tpl></table>',
            {
                compiled: true,
                disableFormats: true,
                formatSact: formatSact,
                formatPact: formatPact,
                formatInq: formatInq
            }
        ),
        editModal: {
            allowAdd: false,
            width: 700,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.User.USERURL + '/activity',
                pageSize: 50,
                tpl: new Ext.XTemplate(
                    '<table width="100%"><tr class="air2-user-act">' +
                      '<td width="20px"><span class="type-icon ' +
                        '<tpl if="SrcActivity">air2-icon-source</tpl>' +
                        '<tpl if="ProjectActivity">air2-icon-project</tpl>' +
                        '<tpl if="Inquiry">air2-icon-inquiry</tpl>' +
                      '"></span></td>' +
                      '<td>' +
                        '<tpl if="SrcActivity">{[this.formatSact(values.SrcActivity)]}</tpl>' +
                        '<tpl if="ProjectActivity">{[this.formatPact(values.ProjectActivity)]}</tpl>' +
                        '<tpl if="Inquiry">{[this.formatInq(values.Inquiry)]}</tpl>' +
                      '</td>' +
                      '<td class="act-dtim">{dtim}</td>' +
                    '</tr></table>',
                    {
                        compiled: true,
                        disableFormats: true,
                        formatSact: formatSact,
                        formatPact: formatPact,
                        formatInq: formatInq
                    }
                )
            }
        }
    });
}